#include "user.h"
#include <iostream>

user::user()
{
    this->setName("");
    this->setAge(0);
    this->setSubLength("haha");
}
user::user(QString name, int age,QString sublength,QString password)
{
    Custom cu;
    QString q_name = name;
    this->setName(q_name);
    this->setAge(age);
    this->setMessage(cu.lastStr(name));
    this->setSubLength(sublength);
    this->setPassword(password);
}

QString user::Name()
{
    return m_name;
}
void user::setName(QString name)
{
    m_name = name;
    Custom cu;
    emit NameChanged();
    setMessage(QString("%1").arg(cu.lastStr(name)));
}

int user::Age()
{
    return m_age;
}
void user::setAge(int age)
{
    m_age = age;
    emit AgeChanged();
    setMessage(QString("%1").arg(age));
}

void user::setSubLength(QString str)
{
    m_subLength = str;
    emit SubLengthChanged();
}

QString user::SubLength()
{
    return m_subLength;
}

void user::setPassword(QString pass)
{
    m_password = pass;
    emit PasswordChanged();
}

QString user::Password()
{
    return m_password;
}

QString user::Message()
{
    return m_message;
}

void user::setMessage(QString message)
{
    m_message = message;
    emit MessageChanged();
}

bool user::checkPass()
{
    Custom cus;
    auto name = this->Name();
    auto pass = this->Password();
    auto lrs = cus.subStringLength(name.toStdString());
    setMessage(cus.lastStr(name));
    setSubLength(QString("%1").arg(lrs));
    auto rs = cus.userInfos("");
    std::cout<<rs.size()<<std::endl;
    if(rs.find(name.toStdString())==rs.end())
        return false;
    if(rs.find(name.toStdString())->second==pass.toStdString())
        return true;
    return false;
}

void user::editOk()
{
    //setMessage("您点击了确定按钮");
}
